#include <func.h>

int main(int argc,char **argv)
{
    ARGS_CHECK(argc,3);
    int fdr = open(argv[1],O_RDONLY);
    ERROR_CHECK(fdr,-1,"open_fdr");
    int fdw = open(argv[2],O_WRONLY);
    ERROR_CHECK(fdw,-1,"open_fdw");

    printf("this is chat1:\n");
    char buf[512] = {0};
    int ret;
    while(1)
    {
        memset(buf,0,sizeof(buf));
        ret = read(STDIN_FILENO,buf,sizeof(buf));
        ERROR_CHECK(ret,-1,"read_ret2");
       
        if(strlen(buf)-1==0)
        {
            printf("only enter,restart\n");
            continue;
        }

        ret = write(fdw,buf,strlen(buf)-1);
        ERROR_CHECK(ret,-1,"write_ret");

        memset(buf,0,sizeof(buf));
        ret = read(fdr,buf,sizeof(buf));
        ERROR_CHECK(ret,-1,"read_ret");
        printf("      recive : %s\n",buf);
    }
    return 0;
}

